{% comment %}

status constants: STARTING, INITIALISING, IMPORTING, IMPORT_COMPLETED, ERROR

{% endcomment %}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
        {% if status == STARTING or status = INITIALISING or status == IMPORTING %}
            {% if not is_paused %}
                <meta http-equiv="refresh" content="{{ refresh_interval }}">
            {% endif %}
        {% endif %}
        
        <title>{{ app_title }}</title>
        <link rel="stylesheet" type="text/css" href="/static/tasks_backup.css" />
        <link rel="shortcut icon" type="image/x-icon" href="/static/favicon.ico" />
        <link rel="icon" type="image/x-icon" href="/static/favicon.ico" />
        
        <script type="text/javascript" src="/static/jquery.js"></script>
        <script type="text/javascript" src="/static/popup.js"></script>
        
        <script type="text/javascript">

            function disableDisplayHtmlButton() {
                document.getElementById("display-tasks-button").value = "Building display page (this may take many minutes) ...";
                document.getElementById("display-tasks-button").innerHTML = "Building display page (this may take many minutes) ...";
                document.getElementById("display-tasks-button").disabled = true;
                // Also disable retrieve button, since clicking it after display button 
                // has been clicked, results in display process being interrupted. 
                // Display button stays disabled, user get selected download file, 
                // but user never sees the display page.
                document.getElementById("retrieve-tasks-button").disabled = true;
            }
            
            function changeCompletedSuboptions() {
                if (document.getElementById("display_completed_tasks").checked) 
                {
                    document.getElementById("dim_completed_tasks").checked = true; // Default
                    document.getElementById("dim_completed_tasks").disabled = false;
                    document.getElementById("display_completed_date_field").checked = true;
                    document.getElementById("display_completed_date_field").disabled = false;
                } else {
                    document.getElementById("dim_completed_tasks").checked = false;
                    document.getElementById("dim_completed_tasks").disabled = true;
                    document.getElementById("display_completed_date_field").checked = false;
                    document.getElementById("display_completed_date_field").disabled = true;
                }
            }
            
            function changeCompletedOptions() {
                if (document.getElementById("due_selection_any_due").checked ||
                    document.getElementById("due_selection_due_now").checked ||
                    document.getElementById("due_selection_overdue").checked)
                {
                    e = false;
                } else {
                    e = true;
                }
                document.getElementById("display_completed_tasks").checked = e;
                changeCompletedSuboptions();
//                document.getElementById("dim_completed_tasks").checked = e;
//                document.getElementById("display_completed_date_field").checked = e;
        }
            
            function changeDisplayCompleted() {
                if (document.getElementById("dim_completed_tasks").checked ||
                    document.getElementById("display_completed_date_field").checked) 
                {
                    document.getElementById("display_completed_tasks").checked = true;
                }
            }
            
            function setDateFields(day, month, year) {
                document.getElementById("due_year").value = year;
                document.getElementById("due_month").value = month + 1; // JS Months are 0-11
                document.getElementById("due_day").value = day;
                yearStr = "0000" + year.toString();
                yearStr = yearStr.substring(yearStr.length - 4);
                monthStr = "00" + (month + 1).toString();
                monthStr = monthStr.substring(monthStr.length -2);
                dayStr = "00" + day.toString();
                dayStr = dayStr.substring(dayStr.length - 2);
                document.getElementById("due_date").innerHTML = yearStr + "-" + monthStr + "-" + dayStr;
            }
            
            function setCurrentDueDate() {
                // Set the current date, which is used when displaying current due tasks.
                // We take the date from the browser, so that the due date is today in the user's current timezone is used
                var today = new Date();
                setDateFields(today.getDate(), today.getMonth(), today.getFullYear());
            }
        
        </script>
        <script type="text/javascript">

          var _gaq = _gaq || [];
          _gaq.push(['_setAccount', 'UA-30118203-1']);
          _gaq.push(['_trackPageview']);

          (function() {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
          })();

        </script>
    </head>

<body onload="changeCompletedSuboptions(); changeCompletedOptions(); changeDisplayCompleted(); setCurrentDueDate()" > 
    <div class="usertitle">
        Authorised user: {{ user_email }} <span class="logout-link">[ <a href="{{ logout_url }}">Log out</a> ]</span>
    </div>


    <h2>{{ app_title }}</h2>
  
    <noscript>
        <br />
        <h3>Javascript must be enabled for full application functionality</h3>
        <br />
    </noscript>
    
    {% if host_msg %}
        <div class="break">
            <h3>{{ host_msg }}</h3>
        </div>
    {% endif %}

    {% if msg %}
        <div class="break">
            <p>Msg = {{ msg }}</p>
		</div>
    {% endif %}
    
    {% if status == "no-record" %}
        <div class="break">
            No import job found for {{ user_email }}
            <br />
            Please click button to start an import
            <form method="GET" action="{{ url_main_page }}">
                <button type="submit">Start import</button>
            </form>
        </div>
    {% endif %}
    
    
    {% if is_paused %}
        <br />
        {% if pause_reason == DAILY_LIMIT_EXCEEDED %}
            <h3>Daily limit exceeded</h3>
            <div class="break">
                This application is running on my personal AppSpot account, which is limited by Google to a total of 5000 task updates per day.
            </div>
            <div class="break">
                The daily quota is reset at midnight Pacific Standard Time (5:00pm Australian Eastern Standard Time, 07:00 UTC).
            </div>
            <div class="take-note break">
                Your import job has been saved. Please rerun <a href="{{ url_home_page }}">{{ app_title }}</a> any time after midnight PST to finish your import.
            </div>
            {% if job_msg %}
                <br />
                <div class="break">
                    {{ job_msg }}
                </div>
            {% endif %}
        {% else %}
            <h3>{{ pause_reason }}</h3>
            {% if job_msg %}
                <br />
                <div class="break">
                    {{ job_msg }}
                </div>
            {% endif %}
        {% endif %}
    {% else %}
    
        {% if status == STARTING or status = INITIALISING or status == IMPORTING %}
            <div class="break">
                This page will auto-refresh every {{ refresh_interval }} seconds to indicate progress.
            </div>
            <div class="break">
                The import will continue in the background even if this window is closed. 
                The import status can be checked at any time by returning to this page.
            </div>
        {% endif %}
        {% if status == IMPORT_COMPLETED %}
            <div class="import-completed-message">
                <div class="take-note-larger">
                    Import completed.
                </div>
                <div class="break">
                    Import method: {{ import_method }}
                    {% if import_tasklist_suffix %}
                        <div class="comment break">
                            Appended "{{ import_tasklist_suffix }}" to imported tasklist names.
                        </div>
                    {% endif %}
                </div>
                <div class="medium-break">
                    {{ job_msg }} 
                </div>
            </div>

{% comment %}
<!--            
            <form action="{{ url_main_page }}" method="get">
                <button type="submit" class="big-button" value="Return to main page">Return to main page</button>
            </form>
-->
{% endcomment %}

            <form>
                <input type="button" class="big-button" onClick="window.location.href = '{{ url_main_page }}'" 
                    value="Return to main page">
            </form>
            
        {% else %}
            <div class="break">
                Status = {{ status }}
            </div>
            {% comment %}
                {% if progress > 0 %}
                    <div class="break">
                        Progress = {{ progress }} of {{ total_num_rows_to_process }}
                    </div>
                {% endif %}
            {% endcomment %}
            {% if job_msg %}
                <div class="break">
                    {{ job_msg }}
                </div>
            {% endif %}
        {% endif %}
    {% endif %}
    
    
        
    {% if error_message %}
        <br />
        <br />
        <br />
        <br />
        <div class="take-note break">
        {{ error_message }}
        </div>
        <div class="break">
            Please report this error at <a href="http:/{{ url_issues_page }}">{{ url_issues_page }}</a>
        </div>
        <br />
        <br />
        <br />
    {% endif %}
    


	<div class="project-footer">
        <div class="break">
            Version {{ app_version }} ({{ upload_timestamp }})
        </div>
        
		<div class="break">
			Questions or comments? Go to <a href="http://{{ url_discussion_group }}">{{ url_discussion_group }}</a>
			or email <a href="mailto:{{ email_discussion_group }}">{{ email_discussion_group }}</a>
		</div>
		<div class="break">
			Please report bugs or suggest improvements at <a href="http:/{{ url_issues_page }}">{{ url_issues_page }}</a>
		</div>
		<div class="break">
			Source code for this project is at <a href="http://{{ url_source_code }}">{{ url_source_code }}</a>
		</div>
	</div>

	<div class="backgroundPopup"></div>

</body>
</html>
